package com.happyrecyclingstation.controller.admin;

import com.happyrecyclingstation.dto.PosJobSeekerQueryDto;
import com.happyrecyclingstation.service.PositionService;
import com.happyrecyclingstation.utils.Result;
import com.happyrecyclingstation.vo.PosDetailVO;
import com.happyrecyclingstation.vo.AdminPosReviewVO;
import com.happyrecyclingstation.vo.HrPosVO;
import com.happyrecyclingstation.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员
 */
@Slf4j
@RestController("adminPositionController")
@RequestMapping("/admin/positions")
public class PositionController {
    @Autowired
    private PositionService positionService;

    /**
     * 查询待审核的职位
     * @return
     */
    @GetMapping("/review")
    public Result getAllPosReview(@RequestParam(defaultValue = "1") Integer currentPage,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询待审核职位:{}，{}", currentPage, pageSize);
        PageResult<AdminPosReviewVO> pendingReviewList = positionService.getPosByStatus(currentPage, pageSize);
        return Result.success(pendingReviewList);
    }

    /**
     * 根据职位id查询职位详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getPosDetail(@PathVariable("id") Integer id){
        log.info("查询职位详情:{}", id);
        PosDetailVO positionDetail = positionService.getPosById(id);
        return Result.success(positionDetail);
    }

    /**
     * 根据id批量通过职位审核
     * @param ids
     * @return
     */
    @PutMapping
    public Result passReview(@RequestBody List<Integer> ids){
        log.info("通过职位审核:{}", ids);
        positionService.passReview(ids);
        return Result.success();
    }

    /**
     * 职位审核不通过
     * @param id
     * @param message
     * @return
     */
    @PutMapping("/{id}")
    public Result rejectReview(@PathVariable("id") Integer id, String message){
        log.info("职位审核不通过:{},{}", id, message);
        positionService.rejectReview(id, message);
        return Result.success();
    }

    /**
     * 管理员查询职位列表
     * @param posQueryParam
     * @return
     */
    @GetMapping
    public Result getPositionsByCondition(PosJobSeekerQueryDto posQueryParam) {
        log.info("管理员查询职位列表：{}", posQueryParam);
        PageResult<HrPosVO> positions = positionService.getAllPos(posQueryParam);
        return Result.success(positions);
    }

}
